
from ninja import Router, ModelSchema
from blog.models import Article
from utils.response import Response
from utils.tools import convert_to_camel_case

router = Router()

class SchemaOut(ModelSchema):
    class Config:
        model = Article
        model_fields = ['id', 'article_title', 'article_cover', 'create_time']


@router.get("/archives/list")
def list_archives(request, current: int, size: int):
    # 处理参数值
    count = Article.objects.filter(is_delete=0, status=1).count()
    archives = Article.objects.filter(is_delete=0, status=1).order_by('-create_time').values('id', 'create_time', 'article_title', 'article_cover')
    _archives = [convert_to_camel_case(archive) for archive in archives]
    offset = size * (current - 1)
    limit: int = size
    recordList = _archives[offset: offset + limit]
    return Response({"count": count, "recordList": recordList})
